import os

from django.conf import settings
from django.views import View

from User.models import User, Order, OrderYard, OrderVip, OrderGoods, OrderRent
from Venue import Constants
from Venue.models import VenueSportYard, Vip, Goods, Rent
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredVenue


class StatisticsView(LoginRequiredVenue,View):
    """ 数据统计 """

    def get(self, request):
        """ 查询 """
        venue = request.user.venue

        lists = {}

        yard = {
            "counts": VenueSportYard.objects.count(),
            "orders": OrderYard.objects.count(),
        }
        lists['yard'] = yard

        vip = {
            "counts": Vip.objects.count(),
            "orders": OrderVip.objects.count(),
        }
        lists['vip'] = vip

        goods = {
            "counts": Goods.objects.count(),
            "orders": OrderGoods.objects.count(),
        }
        lists['goods'] = goods

        rent = {
            "counts": Rent.objects.count(),
            "orders": OrderRent.objects.count(),
        }
        lists['rent'] = rent
        return Res.Json(Res.OK, result=lists)
